package cn.mju.tankfighterbackend.controller

import cn.mju.tankfighterbackend.bean.AjaxResult
import cn.mju.tankfighterbackend.onFalse
import cn.mju.tankfighterbackend.onTrue
import cn.mju.tankfighterbackend.service.CustomerUserService
import cn.mju.tankfighterbackend.toAjaxResult
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("user")
class UserController @Autowired constructor(
    val customerUserService: CustomerUserService
){

    @PostMapping("register")
    fun register(@RequestBody userRegisterReq: UserRegisterReq):AjaxResult<Boolean>{
       return if (customerUserService.registerUser(userRegisterReq.username,userRegisterReq.password)) {
            AjaxResult.success("注册成功!")
        }else{
           AjaxResult.error("用户名已存在!")
       }
    }
}
data class UserRegisterReq(
    val username:String,
    val password:String
)